//
//  MSFoodDetailView.m
//  MSJD
//
//  Created by xiangbo on 2018/9/28.
//  Copyright © 2018 xiangbo. All rights reserved.
//

#import "MSFoodDetailView.h"

@interface MSFoodDetailView ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong)NSArray *dataArray;
@property (nonatomic, strong)UITableView *tableview;

@end

@implementation MSFoodDetailView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        [self addSubview:self.tableview];
        
        [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self);
        }];
    }
    return self;
}

#pragma mark -UITableViewDelegate and DataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell" forIndexPath:indexPath];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 0;
}
#pragma mark - Property

- (UITableView *)tableview{
    if (!_tableview) {
        _tableview = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        for (NSString *identifier in MSIdentifierDic.allKeys) {
            [_tableview registerClass:NSClassFromString(MSIdentifierDic[identifier]) forCellReuseIdentifier:identifier];
        }
    }
    return _tableview;
}

- (NSArray *)dataArray{
    if (!_dataArray) {
        NSMutableArray *tempArray = [NSMutableArray array];
        for (NSString *key in [[MSIdentifierDic allKeys] sortedArrayUsingSelector:@selector(compare:)]) {
            MSFoodData *data = [[MSFoodData alloc] init];
            data.showType = key;
            [tempArray addObject:data];
        }
        
        MSFoodData *data = [[MSFoodData alloc] init];
        data.showType = @"d";
        [tempArray insertObject:data atIndex:0];
        
        _dataArray = tempArray.copy;
    }
    return _dataArray;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
